package edu.hawaii.myisern.action;

import com.meterware.httpunit.WebLink;
import com.meterware.httpunit.WebResponse;
import static org.junit.Assert.assertEquals;

import org.junit.Test;

/**
 * Tests logout operation of the Logout Action Bean.
 *
 * @author Lisa Chen
 */
public class TestLogoutActionBean extends TestWeb {

 
  /**
   * Tests the Isern logout form.
   *
   * @throws Exception If problems occur
   */
  @Test
  public void testLogout() throws Exception {
//    WebConversation conversation = new WebConversation();
//    
//    // Get the login form and check that we have the right form.
//    String Url = testHost + applicationName + "/login.jsp";
//    WebResponse response = conversation.getResponse(Url);
//    assertEquals("Retrieving login page to login then logout.", 
//        "My ISERN Login", response.getTitle());
//    
//    // First, successfully login to the system then check forwarded to index.jsp.
//    WebForm loginForm = response.getFormWithID("LoginForm");
//    WebRequest loginRequest = loginForm.getRequest();
//    loginRequest.setParameter("username", "myisern");
//    loginRequest.setParameter("password", "isern2008");
    WebResponse response = conversation.getResponse(getAppUrl() + "/researchers.jsp");
    assertEquals("Check login forwarded to index.jsp which begins at Researchers", 
        "ISERN - Researchers", response.getTitle());
    
    // Click on logout link on index.jsp
    WebLink logoutLink = response.getLinkWith("logout");
    response = logoutLink.click();
    assertEquals("Check clicking logout forwards to login page.", 
        "My ISERN Login", response.getTitle());
    // Try to access a non public page in MyIsern after logout
    String Url = getAppUrl() + "/researcher_form.jsp";
    response = conversation.getResponse(Url);
    assertEquals("Check access to non public page is redirected", 
        "My ISERN Login", response.getTitle());
    
  }

}
